```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主键回填技术详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        .code-block {
            background: #f8f9fa;
            border-left: 4px solid #6e8efb;
        }
        .highlight {
            background: rgba(110, 142, 251, 0.1);
            padding: 2px 4px;
            border-radius: 4px;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="serif text-4xl md:text-5xl font-bold mb-4">主键回填技术详解</h1>
            <p class="text-xl max-w-2xl mx-auto">数据库操作中的关键技巧与最佳实践</p>
            <div class="mt-8">
                <span class="inline-block bg-white text-indigo-600 px-4 py-2 rounded-full font-medium shadow-md">数据持久化</span>
                <span class="inline-block bg-white text-indigo-600 px-4 py-2 rounded-full font-medium shadow-md ml-2">MyBatis</span>
                <span class="inline-block bg-white text-indigo-600 px-4 py-2 rounded-full font-medium shadow-md ml-2">数据库设计</span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-4xl">
        <!-- Introduction -->
        <div class="bg-white rounded-xl p-8 mb-12 card">
            <div class="flex items-center mb-4">
                <i class="fas fa-database text-indigo-500 text-2xl mr-3"></i>
                <h2 class="serif text-2xl font-bold">什么是主键回填？</h2>
            </div>
            <div class="prose max-w-none">
                <p>主键回填是指在数据库执行插入操作后，将数据库生成的主键值回填到实体对象中的主键属性中。这在使用自增主键或其他方式生成主键值时特别有用。</p>
                <p>通常，在执行插入操作后，需要获取新插入数据的主键值，以便进行后续操作或展示。主键回填的目的就是在插入操作完成后，能够方便地获取到新生成的主键值，从而实现数据的完整性和一致性。</p>
            </div>
        </div>

        <!-- Solutions -->
        <div class="bg-white rounded-xl p-8 mb-12 card">
            <div class="flex items-center mb-4">
                <i class="fas fa-lightbulb text-yellow-500 text-2xl mr-3"></i>
                <h2 class="serif text-2xl font-bold">解决方案有哪些?</h2>
            </div>
            
            <!-- Solution 1 -->
            <div class="mb-8">
                <div class="flex items-center mb-2">
                    <span class="bg-indigo-100 text-indigo-800 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-3">1</span>
                    <h3 class="serif text-xl font-semibold">使用数据库自增主键</h3>
                </div>
                <p class="ml-11">如果数据库表的主键是自增的，在插入数据后，数据库会自动生成主键值，MyBatis 会将该值回填到实体对象的对应属性中。在插入操作完成后，可以通过实体对象获取到新生成的主键值。</p>
            </div>
            
            <!-- Solution 2 -->
            <div class="mb-8">
                <div class="flex items-center mb-2">
                    <span class="bg-indigo-100 text-indigo-800 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-3">2</span>
                    <h3 class="serif text-xl font-semibold">使用 selectKey 元素</h3>
                </div>
                <p class="ml-11">如果数据库表的主键不是自增的，或者需要使用其他方式生成主键值，可以在插入数据时使用 <span class="highlight">selectKey</span> 元素来实现主键回填。</p>
                
                <div class="ml-11 mt-4 code-block p-4 rounded">
                    <pre class="font-mono text-sm overflow-x-auto">
&lt;insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="id"&gt;
    &lt;!-- 在插入操作之后执行查询来生成主键值，并将查询结果回填到 id 属性 --&gt;
    &lt;selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long"&gt;
        SELECT LAST_INSERT_ID()
    &lt;/selectKey&gt;
    INSERT INTO user (username, password) VALUES (#{username}, #{password})
&lt;/insert&gt;</pre>
                </div>
                <p class="ml-11 mt-3">在上面的示例中，<span class="highlight">useGeneratedKeys="true"</span> 表示使用数据库自动生成的主键值，<span class="highlight">keyProperty="id"</span> 指定了回填主键值的属性名。<span class="highlight">selectKey</span> 元素中的查询语句 <span class="highlight">SELECT LAST_INSERT_ID()</span> 获取最近一次插入操作生成的自增主键值，将其回填到 <span class="highlight">id</span> 属性中。</p>
            </div>
            
            <!-- Solution 3 -->
            <div>
                <div class="flex items-center mb-2">
                    <span class="bg-indigo-100 text-indigo-800 font-bold rounded-full w-8 h-8 flex items-center justify-center mr-3">3</span>
                    <h3 class="serif text-xl font-semibold">使用UUID或Redis维护ID</h3>
                </div>
                <p class="ml-11">在某些情况下，你可能希望避免使用数据库生成的主键，转而使用UUID或Redis来管理ID。</p>
                
                <div class="ml-11 mt-4 code-block p-4 rounded">
                    <pre class="font-mono text-sm overflow-x-auto">
// 1、先生产一个ID
Long id = UUIDUtils.getId();

// 2.把id添加对象中
order.setId(id);

// 3、插入订单
orderMapper.insert(order);

// 4.插入订单详情
orderDetail.setOrderId(id);
orderDetailMapper.insert(orderDetail);</pre>
                </div>
            </div>
        </div>

        <!-- Visualization -->
        <div class="bg-white rounded-xl p-8 card">
            <div class="flex items-center mb-4">
                <i class="fas fa-project-diagram text-green-500 text-2xl mr-3"></i>
                <h2 class="serif text-2xl font-bold">主键回填流程可视化</h2>
            </div>
            <div class="mermaid">
                sequenceDiagram
                    participant Client
                    participant Application
                    participant Database
                    Client->>Application: 提交数据(无ID)
                    Application->>Database: 执行INSERT语句
                    Database-->>Application: 生成并返回主键(ID)
                    Application->>Application: 将ID回填到对象
                    Application-->>Client: 返回完整对象(含ID)
            </div>
        </div>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-200 py-8">
        <div class="container mx-auto px-6 text-center">
            <div class="mb-4">
                <h3 class="text-xl font-bold">技术小馆</h3>
                <p class="text-gray-400">专注技术分享与交流</p>
            </div>
            <div>
                <a href="http://www.yuque.com/jtostring" class="text-blue-300 hover:text-white transition-colors duration-300">
                    <i class="fas fa-external-link-alt mr-1"></i> http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            },
            sequence: {
                diagramMarginX: 50,
                diagramMarginY: 10,
                boxTextMargin: 5,
                noteMargin: 10,
                messageMargin: 35,
                mirrorActors: false
            }
        });
    </script>
</body>
</html>
```